<template>
  <a-card :bordered="false" style="height: 100%;">
    <a-spin :spinning="loading">
      <a-tree
        showLine
        :selectedKeys="selectedKeys"
        :treeData="treeData"
        @select="handleTreeSelect"
      />
    </a-spin>
  </a-card>
</template>

<script>

  import { getAction } from '@/api/manage'
  import YchConstant from "@/api/YchConstant";

  export default {
    name: 'GroupTree',
    props: {
      value: {
        type: String,
        default: null
      }
    },
    data () {
      return {
        theExpandedKeys:[],
        treeData:[],
        loading:false,
        url:{
          getGroupTree: YchConstant.PREFIX_EFORM + "/manage/actAppGroup/getAllGroupTree",
        }
      }
    },
    computed: {
      selectedKeys () {
        return this.value ? [this.value] : []
      },

    },
    created() {
      this.queryGroupTree()
    },
    methods: {
      queryGroupTree() {
        getAction(this.url.getGroupTree, {}).then((res) => {
          if (res.success) {
            this.treeData = res.result;
          } else {
            this.messageUtil.warning(res.message)
          }
        });
      },
      handleTreeSelect (selectedKeys) {
        this.$emit('input', selectedKeys[0])
      },

    }
  }
</script>
